package cn.dyw.cloudmusic.dao;

import cn.dyw.cloudmusic.entity.Comment;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CommentMapper {
    /**
     *
     */
    @Delete({
            "delete from comment",
            "where comment_id = #{commentId,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer commentId);

    /**
     *
     */
    @Insert({
            "insert into comment (comment_id, user_id, ",
            "comment_location_type, parent_comment_id, ",
            "liked_count, liked, expression_url, ",
            "time, content, ",
            "music_id)",
            "values (#{commentId,jdbcType=INTEGER}, #{userId,jdbcType=INTEGER}, ",
            "#{commentLocationType,jdbcType=INTEGER}, #{parentCommentId,jdbcType=INTEGER}, ",
            "#{likedCount,jdbcType=INTEGER}, #{liked,jdbcType=BIT}, #{expressionUrl,jdbcType=VARCHAR}, ",
            "#{time,jdbcType=TIMESTAMP}, #{content,jdbcType=VARCHAR}, ",
            "#{musicId,jdbcType=VARCHAR})"
    })
    int insert(Comment record);

    @Insert({
            "insert into comment (comment_id, user_id, ",
            "comment_location_type, parent_comment_id, ",
            "liked_count, liked, expression_url, ",
            "time, content, ",
            "music_id)",
            "values (#{comment.commentId,jdbcType=INTEGER}, #{comment.user.userId,jdbcType=INTEGER}, ",
            "#{comment.commentLocationType,jdbcType=INTEGER}, #{comment.parentCommentId,jdbcType=INTEGER}, ",
            "#{comment.likedCount,jdbcType=INTEGER}, #{comment.liked,jdbcType=BIT}, #{comment.expressionUrl,jdbcType=VARCHAR}, ",
            "#{comment.time,jdbcType=TIMESTAMP}, #{comment.content,jdbcType=VARCHAR}, ",
            "#{musicId,jdbcType=VARCHAR})"
    })
    int insertVo(@Param("comment") cn.dyw.cloudmusic.music.vo.Comment record, @Param("musicId") String id);

    int insertList(@Param("comments") List<cn.dyw.cloudmusic.music.vo.Comment> records, @Param("musicId") String id);

    /**
     *
     */
    int insertSelective(Comment record);

    /**
     *
     */
    @Select({
            "select",
            "comment_id, user_id, comment_location_type, parent_comment_id, liked_count, ",
            "liked, expression_url, time, content, music_id",
            "from comment",
            "where comment_id = #{commentId,jdbcType=INTEGER}"
    })
    @ResultMap("cn.dyw.cloudmusic.dao.CommentMapper.BaseResultMap")
    Comment selectByPrimaryKey(Integer commentId);

    /**
     * 查找所有的评论
     * @param musicId
     * @return
     */
    @Select("select content from comment where music_id = #{musicId}")
    List<String> selectAllByMusicId(String musicId);

    /**
     *
     */
    int updateByPrimaryKeySelective(Comment record);

    /**
     *
     */
    @Update({
            "update comment",
            "set user_id = #{userId,jdbcType=INTEGER},",
            "comment_location_type = #{commentLocationType,jdbcType=INTEGER},",
            "parent_comment_id = #{parentCommentId,jdbcType=INTEGER},",
            "liked_count = #{likedCount,jdbcType=INTEGER},",
            "liked = #{liked,jdbcType=BIT},",
            "expression_url = #{expressionUrl,jdbcType=VARCHAR},",
            "time = #{time,jdbcType=TIMESTAMP},",
            "content = #{content,jdbcType=VARCHAR},",
            "music_id = #{musicId,jdbcType=VARCHAR}",
            "where comment_id = #{commentId,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Comment record);
}